﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Young3.FMSearch.Business.Offsets;
using Young3.FMSearch.Business.Managers;

namespace Young3.FMSearch.Business.Entities.InGame
{
    public class Stadium : BaseObject
    {
        public Stadium(int memoryAddress)
            : base(memoryAddress)
        { }

        // Properties
        public int FieldLength
        {
            get
            {
                return ProcessManager.ReadInt16(MemoryAddress + StadiumOffsets.Length);
            }
            set
            {
                ProcessManager.WriteInt16(value, MemoryAddress + StadiumOffsets.Length);
            }
        }

        public int ExpansionCapacity
        {
            get
            {
                return ProcessManager.ReadInt32(MemoryAddress + StadiumOffsets.ExpansionCapacity);
            }
            set
            {
                ProcessManager.WriteInt32(value, MemoryAddress + StadiumOffsets.ExpansionCapacity);
            }
        }

        public int SeatingCapacity
        {
            get
            {
                return ProcessManager.ReadInt32(MemoryAddress + StadiumOffsets.SeatingCapacity);
            }
            set
            {
                ProcessManager.WriteInt32(value, MemoryAddress + StadiumOffsets.SeatingCapacity);
            }
        }


        public int StadiumCapacity
        {
            get
            {
                return ProcessManager.ReadInt32(MemoryAddress + StadiumOffsets.StadiumCapacity);
            }
            set
            {
                ProcessManager.WriteInt32(value, MemoryAddress + StadiumOffsets.StadiumCapacity);
            }
        }

        public int UsedCapacity
        {
            get
            {
                return ProcessManager.ReadInt32(MemoryAddress + StadiumOffsets.UsedCapacity);
            }
            set
            {
                ProcessManager.WriteInt32(value, MemoryAddress + StadiumOffsets.UsedCapacity);
            }
        }

        public int FieldWidth
        {
            get
            {
                return ProcessManager.ReadInt16(MemoryAddress + StadiumOffsets.Width);
            }
            set
            {
                ProcessManager.WriteInt16(value, MemoryAddress + StadiumOffsets.Width);
            }
        }

        public string Name
        {
            get
            {
                return ProcessManager.ReadString(MemoryAddress + StadiumOffsets.Name, null);
            }
        }

        public int NearbyStadiumAddress
        {
            get
            {
                return ProcessManager.ReadInt32(MemoryAddress + StadiumOffsets.NearbyStadium);
            }
            set
            {
                ProcessManager.WriteInt32(value, MemoryAddress + StadiumOffsets.NearbyStadium);
            }
        }

        public Stadium NearbyStadium
        {
            get
            {
                try
                {
                    return new Stadium(NearbyStadiumAddress);
                }
                catch
                {
                    return null;
                }
            }
            set { NearbyStadiumAddress = value.MemoryAddress; }
        }

        public byte Decay
        {
            get
            {
                return ProcessManager.ReadByte(MemoryAddress + StadiumOffsets.Decay);
            }
            set
            {
                ProcessManager.WriteByte(value, MemoryAddress + StadiumOffsets.Decay);
            }
        }

        public int ID
        {
            get
            {
                return ProcessManager.ReadInt32(MemoryAddress + StadiumOffsets.StadiumID);
            }
        }

        public int CityAddress
        {
            get
            {
                return ProcessManager.ReadInt32(MemoryAddress + StadiumOffsets.City);
            }
            set
            {
                ProcessManager.WriteInt32(value, MemoryAddress + StadiumOffsets.City);
            }
        }

        public City City
        {
            get
            {
                try
                {
                    return new City(CityAddress);
                }
                catch
                {
                    return null;
                }
            }
            set { CityAddress = value.MemoryAddress; }
        }

        public int OwnerAddress
        {
            get
            {
                return ProcessManager.ReadInt32(MemoryAddress + StadiumOffsets.Owner);
            }
            set
            {
                ProcessManager.WriteInt32(value, MemoryAddress + StadiumOffsets.Owner);
            }
        }

        public Club Owner
        {
            get
            {
                try
                {
                    return new Club(OwnerAddress);
                }
                catch
                {
                    return null;
                }
            }
            set { OwnerAddress = value.MemoryAddress; }
        }
    }
}
